<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/layout/common.xhtml">
	<ui:define name="body">
		<h:form id="form" acceptcharset="ISO-8859-1">
			<p:panel header="#{msg['massai.lancarServicoProducao.header']}">
				<h:panelGrid columns="2">
					<h:panelGrid>
						<h:outputLabel value="#{msg['massai.lancarServicoProducao.tipoFolha']}" for="tipoFolha" />
						<p:selectOneMenu tabindex="1"
							value="#{lancamentoProducaoBean.planilha.tipoFolha}" 
							id="tipoFolha" style="width: 120px;">
							<f:selectItems value="#{lancamentoProducaoBean.tipoFolha()}" />
						</p:selectOneMenu>
					</h:panelGrid>
					
					<h:panelGrid>
						<h:outputLabel value="#{msg['massai.lancarServicoProducao.competencia']}" for="competencia" />
						<p:inputMask  tabindex="2"
							value="#{lancamentoProducaoBean.planilha.competencia}" 
							mask="99/9999" id="competencia" converter="competenciaConverter" 
							style="width: 70px; text-align: right;" />
					</h:panelGrid>
				</h:panelGrid>
			</p:panel>
			<p:toolbar>
				<f:facet name="left">
					<p:commandButton value="#{msg['massai.comum.pesquisar']}" update="form,:messages"
						actionListener="#{lancamentoProducaoBean.pesquisar()}" tabindex="3" />
					<span class="ui-separator">
		                <span class="ui-icon ui-icon-grip-dotted-vertical" />
		            </span>
		            <p:commandButton value="#{msg['massai.comum.incluir']}" tabindex="4" 
		            	ajax="false" immediate="true" action="lancarServicoProducaoCadastro" />
				</f:facet>
			</p:toolbar>
			
			<p:dataTable style="margin-top: 15px;" emptyMessage="#{msg['massai.comum.emptyMessage']}" 
				value="#{lancamentoProducaoBean.listaPlanilhaLancamento}" var="planilha" sortMode="multiple" rows="10" paginator="true"
		                paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
		                currentPageReportTemplate="({currentPage} de {totalPages})" paginatorPosition="bottom" paginatorAlwaysVisible="false">

				<f:facet name="header"><h:outputText value="#{msg['massai.lancarServicoProducao.lancamentoPlanilhas']}" /></f:facet>

				<p:column headerText="#{msg['massai.manterGrupoProducao.codigo']}" sortBy="#{planilha.id}" width="70">
					<h:outputText value="#{genericUtilBean.completarZerosEsquerda(planilha.id, 8)}" />
				</p:column>

				<p:column headerText="#{msg['massai.manterGrupoProducao.obra']}" sortBy="#{planilha.obra.codigoDepto}">
					<h:outputText value="#{genericUtilBean.completarZerosEsquerda(planilha.obra.codigoColigada, 8)} - #{planilha.obra.codigoDepto} - #{planilha.obra.nomeFantasia ne null ? planilha.obra.nomeFantasia : planilha.obra.nome}" />
				</p:column>

				<p:column headerText="#{msg['massai.lancarServicoProducao.competencia']}" sortBy="#{planilha.competencia}" width="100">
					<h:outputText value="#{planilha.competencia}" converter="competenciaConverter" />
				</p:column>

				<p:column headerText="#{msg['massai.lancarServicoProducao.tipoFolha']}" sortBy="#{planilha.tipoFolha}" width="100">
					<h:outputText value="#{planilha.tipoFolha.descricao}" />
				</p:column>

				<p:column headerText="#{msg['massai.manterGrupoProducao.status']}" sortBy="#{planilha.status}" width="100">
					<h:outputText value="#{planilha.status.descricao}" />
				</p:column>

				<p:column headerText="#{msg['massai.comum.finalizar']}" width="50" style="text-align: center;">
					<h:commandLink rendered="#{!lancamentoProducaoBean.verificaAprovada(planilha)}"
						onclick="if (! window.confirm('Após finalizada, a Planilha só poderá ser alterada em status de Revisão.') ) {return false}" 
		            	actionListener="#{lancamentoProducaoBean.finalizaPlanilha()}">
						<img src="#{facesContext.externalContext.requestContextPath}/imagens/ico_down01.png" 
							width="16" height="16" border="0" name="#{msg['massai.comum.finalizar']}" 
							alt="#{msg['massai.comum.finalizar']}" title="#{msg['massai.comum.finalizar']} Planilha" />
							<f:param name="id" value="#{planilha.id}" />
					</h:commandLink>
				</p:column>

				<p:column headerText="#{msg['massai.comum.editar']}" width="32" style="text-align: center;">
					<h:link outcome="lancarServicoProducaoCadastro?param=#{planilha.id}">
						<img src="#{facesContext.externalContext.requestContextPath}/imagens/ico_edit.png" 
							width="16" height="16" border="0" name="#{msg['massai.comum.editar']}" 
							title="#{msg['massai.comum.editar']}" alt="#{msg['massai.comum.editar']}" />
					</h:link>
				</p:column>

				<p:column headerText="#{msg['massai.comum.excluir']}" width="42" style="text-align: center;">
					<p:commandLink rendered="#{!lancamentoProducaoBean.verificaAprovada(planilha)}" 
						onclick="if (! window.confirm('Deseja excluir esse registro?') ) {return false}" 
						actionListener="#{lancamentoProducaoBean.deletaPlanilha()}" update=":form,:messages">
						<img src="#{facesContext.externalContext.requestContextPath}/imagens/ico_remove.png" 
							width="16" height="16" border="0" name="#{msg['massai.comum.excluir']}" 
							title="#{msg['massai.comum.excluir']}" alt="#{msg['massai.comum.excluir']}" />
						<f:param name="id" value="#{planilha.id}" />
					</p:commandLink>
				</p:column>
			</p:dataTable>
		</h:form>
	</ui:define>
</ui:composition>
</html>